package com.wwwarehouse.taskcenter.adapter.job_point;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.wwwarehouse.taskcenter.R;
import com.wwwarehouse.taskcenter.bean.job_point.DimensionBean;

import java.util.List;

/**
 * Created by Jackie on 2017/10/27.
 * 维度适配器
 */

public class DimensionAdapter extends BaseAdapter {
    private Context mContext;
    private List<DimensionBean> mDimensionList;
    private int mItemHeight;

    public DimensionAdapter(Context context, List<DimensionBean> dimensionList, int itemHeight) {
        this.mContext = context;
        this.mDimensionList = dimensionList;
        this.mItemHeight = itemHeight;
    }

    @Override
    public int getCount() {
        return mDimensionList == null ? 0 : mDimensionList.size();
    }

    @Override
    public Object getItem(int position) {
        return mDimensionList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        DimensionBean dimensionBean = mDimensionList.get(position);

        ViewHolder holder;

        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_dimension, null);

            holder = new ViewHolder();
            holder.iconImg = (ImageView) convertView.findViewById(R.id.iv_icon);
            holder.nameTxt = (TextView) convertView.findViewById(R.id.tv_name);
            holder.checkImg = (ImageView) convertView.findViewById(R.id.iv_check);

            convertView.setTag(holder);

            AbsListView.LayoutParams params =  new AbsListView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
            params.height = mItemHeight;
            convertView.setLayoutParams(params);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.iconImg.setImageResource(dimensionBean.getResId());
        holder.nameTxt.setText(dimensionBean.getName());

        if (dimensionBean.isFinish()) {
            holder.checkImg.setVisibility(View.VISIBLE);
        } else {
            holder.checkImg.setVisibility(View.GONE);
        }

        return convertView;
    }

    class ViewHolder {
        private ImageView iconImg;
        private TextView nameTxt;
        private ImageView checkImg;
    }
}
